<?

require_once ("application.fieldset.inc");

global $_GLOBAL_DBH;
global $_OBJECT_IFACE_PANEL;

$right = $_GLOBAL_DBH->query ("SELECT right_id AS id FROM workgroup_role_module_rights WHERE id={$_REQUEST["role_right_id"]}");
$right = $_GLOBAL_DBH->fetch_object ($right);

$fieldset_data = preg_match ("/addnew|create/", $_REQUEST["fs_action_data"]) ?

	new Fieldset (array (
	db_conn=>$_GLOBAL_DBH,
	relation=>"workgroup_role_module_right_data_view",
	relation_redirect=>"workgroup_role_module_right_data",
	prefix=>"urmrdv_",
	fieldset=>array (
		array (name=>"id",label=>"ID",type=>"numeric",
				input=>"hidden",primary_key=>true),
		array (name=>"workgroup_id",label=>"ID",type=>"numeric",
				value=>$_REQUEST["workgroup_id"],
				input=>"hidden"),
		array (name=>"role_id",label=>"ID",type=>"numeric",
				value=>$_REQUEST["role_id"],
				input=>"hidden"),
		array (name=>"module_id",label=>"ID",type=>"numeric",
				value=>$_REQUEST["role_module_id"],
				input=>"hidden"),
		array (name=>"right_id",label=>"ID",type=>"numeric",
				value=>$_REQUEST["role_right_id"],
				input=>"hidden"),
		array (name=>"data_id",label=>"Select Right Data",type=>"numeric",
				relation=>array(foreign=>"data",key=>"id",
						field=>"title"),
				input=>"select",
				options=>"_app_select_query",
				options_params=>"SELECT id,title FROM data WHERE right_id={$right->id} AND id NOT IN (SELECT data_id FROM workgroup_role_module_right_data WHERE right_id={$_REQUEST["role_right_id"]})",
				columns=>array (key=>"id",value=>"title"),
		),
		array (name=>"access",label=>"Right Access",type=>"character",
				input=>"select",
				value=>"exclusive",
				options=>array (
					array (id=>"public",name=>"Public"),
					array (id=>"private",name=>"Private"),
					array (id=>"exclusive",name=>"Exclusive"),
				),
				columns=>array(key=>"id",value=>"name"),
		),
	)))

	:

	new Fieldset (array (
	db_conn=>$_GLOBAL_DBH,
	relation=>"workgroup_role_module_right_data_view",
	relation_redirect=>"workgroup_role_module_right_data",
	prefix=>"urmrdv_",
	fieldset=>array (
		array (name=>"id",label=>"ID",type=>"numeric",
				value=>isset ($_REQUEST["urmrdv_id"]) ?
					$_REQUEST["urmrdv_id"] :
					$_REQUEST["role_data_id"],
				input=>"hidden",primary_key=>true),
		array (name=>"code",label=>"Code",type=>"alphanumeric",
				excluded=>true,
				disabled=>true,
				input=>"field"),
		array (name=>"title",label=>"Title",type=>"alphanumeric",
				excluded=>true,
				disabled=>true,
				input=>"field"),
		array (name=>"access",label=>"Right Access",type=>"character",
				input=>"select",
				value=>"exclusive",
				options=>array (
					array (id=>"public",name=>"Public"),
					array (id=>"private",name=>"Private"),
					array (id=>"exclusive",name=>"Exclusive"),
				),
				columns=>array(key=>"id",value=>"name"),
		),
		array (name=>"details",label=>"Details",type=>"alphanumeric",
				excluded=>true,
				disabled=>true,
				input=>"textarea",rows=>5),
	)
));

$fieldset_data->parse ();

$return = "/fs_workgroups.php?fs_tab_modules=rights&fs_action=view&fs_tab=roles&fs_tab_option=fs_roles&fs_action_modules=view&fs_tab_option_modules=fs_rights&fs_action_rights=view&workgroup_id={$_REQUEST["workgroup_id"]}&role_id={$_REQUEST["role_id"]}&role_module_id={$_REQUEST["role_module_id"]}&role_right_id={$_REQUEST["role_right_id"]}";

$fs_options = array (
	addnew=>array (label=>"Add New"),
	create=>array (label=>"Create"),
	modify=>array (label=>"Modify"),
	remove=>array (label=>"Remove"),
	update=>array (label=>"Update"),
	cancel=>array (label=>"Cancel"),
	delete=>array (label=>"Delete",
			redirect=>dirname ($_SERVER["PHP_SELF"]) . $return),
	canret=>array (label=>"Cancel",
			redirect=>dirname ($_SERVER["PHP_SELF"]) . $return),
	close=>array (label=>"Close",
			redirect=>dirname ($_SERVER["PHP_SELF"]) . $return ),
);

$image_options = array (size=>$_REQUEST["_img_size"]);

list ($fs_input, $fs_action, $store, $valid, $success) =

	_app_process_fieldset (array (
		fieldset=>$fieldset_data,
		fs_options=>$fs_options,
		fs_action=>($_REQUEST["fs_action_data"] ?
				$_REQUEST["fs_action_data"] :
				"addnew"),
		fs_action_field=>"fs_action_data",
		fs_primary_key=>"role_data_id",
		fs_prefix=>"urmrdv_",
));

$_OBJECT_FIELDSET_CONTROL =_app_create_fieldset_object (array (
	fieldset_id=>"fs_role_module_right_data",
	db_conn=>$_GLOBAL_DBH,
	fieldset=>$fieldset_data,
	fs_action=>$fs_action,
	fs_action_field=>"fs_action_data",
	fs_title=>"&nbsp;&raquo;&nbsp;Right Data",
	fs_input=>$fs_input,
	fs_link=>"fs_workgroups.php?fs_tab_modules=rights&fs_action=view&fs_tab=roles&fs_tab_option=fs_roles&fs_action_modules=view&fs_tab_option_modules=fs_rights&fs_action_rights=view&fs_action_data=view&workgroup_id={$_REQUEST["workgroup_id"]}&role_id={$_REQUEST["role_id"]}&role_module_id={$_REQUEST["role_module_id"]}&role_right_id={$_REQUEST["role_right_id"]}&role_data_id={$_REQUEST["role_data_id"]}",
	fs_options=>$fs_options,
	fs_prefix=>"urmrdv_",
));

$_OBJECT_IFACE_TABBING_PANEL->insert_container ($_OBJECT_FIELDSET_CONTROL);

?>
